/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class KeyboardEventsTests {
	@SuppressWarnings("rawtypes")
	private List<IKeyboardEvents>	events	= new ArrayList<IKeyboardEvents>();

	@Before
	public void setup() {
		this.events.add(new A());
		this.events.add(new Caption());
		this.events.add(new Div());
		this.events.add(new P());
		this.events.add(new Span());
		this.events.add(new Table());
		this.events.add(new TBody());
		this.events.add(new Td());
		this.events.add(new TFoot());
		this.events.add(new THead());
		this.events.add(new Tr());
		this.events.add(new Form());
		this.events.add(new Image());
		this.events.add(new CheckBox());
		this.events.add(new File());
		this.events.add(new Hidden());
		this.events.add(new InputButton());
		this.events.add(new InputImage());
		this.events.add(new Reset());
		this.events.add(new Submit());
		this.events.add(new Text());
		this.events.add(new Password());
		this.events.add(new OptGroup());
		this.events.add(new Option());
		this.events.add(new Select());
		this.events.add(new HtmlObject());
	}

	@Test
	public void checkEm() {
		for (final IKeyboardEvents<PageElement> e : this.events) {
			this.checkOnKeyDown(e);
			this.checkOnKeyPress(e);
			this.checkOnKeyUp(e);
		}
	}

	@SuppressWarnings("rawtypes")
	public void checkOnKeyDown(final IKeyboardEvents _e) {
		final String scriptlet = "keyDown()";
		_e.setOnKeyDown(scriptlet);
		final String onKeyDown = _e.getOnKeyDown();
		assertEquals(scriptlet, onKeyDown);
	}

	@SuppressWarnings("rawtypes")
	public void checkOnKeyPress(final IKeyboardEvents _e) {
		final String scriptlet = "keypress()";
		_e.setOnKeyPress(scriptlet);
		final String onKeyDown = _e.getOnKeyPress();
		assertEquals(scriptlet, onKeyDown);
	}

	@SuppressWarnings("rawtypes")
	public void checkOnKeyUp(final IKeyboardEvents _e) {
		final String scriptlet = "keyup()";
		_e.setOnKeyUp(scriptlet);
		final String onKeyDown = _e.getOnKeyUp();
		assertEquals(scriptlet, onKeyDown);
	}
}
